home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 11 - 1995 / 11.02 Feb 95 / 11.02 Challenge / SolveBottomEdges.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-10  |  3.3 KB  |  115 lines  |  [TEXT/KAHL]

  1. /*
  2.  
  3.     SolveRubiksCube
  4.     Copyright (c) 1994  J Robert Boonstra
  5.         
  6. */
  7.  
  8. #pragma options(honor_register,assign_registers)
  9.  
  10. #include "rubik.h"
  11. #include "transform.h"
  12.  
  13. Boolean SolveBottomEdges(register RubiksCube *rub)
  14. {
  15. short loopCount;
  16.  
  17. /**********************************************************
  18.  * 
  19.  * STEP 6:  Move edge cubes in bottom layer into position.
  20.  *
  21.  *********************************************************/
  22.   if (DF_F == F || DF_D == F) {              /* FD in pos */
  23.     if (DL_L == R || DL_D == R) {       /* BD->LD->RD->BD */
  24.       B2D1R3L1B2R1L3D1B2;
  25.     } else if (DR_R == L || DR_D == L) {/* BD->RD->LD->BD */
  26.       B2D3R3L1B2R1L3D3B2;
  27.     } 
  28.   } else if (DL_L == L || DL_D == L) {       /* LD in pos */
  29.     if (DB_B == F || DB_D == F) {       /* RD->BD->FD->RD */
  30.       R2D1F3B1R2F1B3D1R2;
  31.     } else if (DF_F == B || DF_D == B) {/* RD->FD->BD->RD */
  32.       R2D3F3B1R2F1B3D3R2;
  33.     }
  34.   } else if (DR_R == R || DR_D == R) {       /* RD in pos */
  35.     if (DF_F == B || DF_D == B) {       /* LD->FD->BD->LD */
  36.       L2D1B3F1L2B1F3D1L2;
  37.     } else if (DB_B == F || DB_D == F) {/* LD->BD->FD->LD */
  38.       L2D3B3F1L2B1F3D3L2;
  39.     }
  40.   } else if (DB_B == B || DB_D == B) {       /* BD in pos */
  41.     if (DR_R == L || DR_D == L) {       /* FD->RD->LD->FD */
  42.       F2D1L3R1F2L1R3D1F2;
  43.     } else if (DL_L == R || DL_D == R) {/* FD->LD->RD->FD */
  44.       F2D3L3R1F2L1R3D3F2;
  45.     }
  46.   } else {
  47.     /* There are no edges in their proper place. */
  48.     if (DF_F == L || DF_D == L) {
  49.       F1L1D1L3D3F2R3D3R1D1F1;
  50.     } else if (DF_F == B || DF_D == B) {
  51.       R2L2U1R2L2D2R2L2U1R2L2;
  52.     } else if (DF_F == R || DF_D == R) {
  53.       R1F1D1F3D3R2B3D3B1D1R1;
  54.     }
  55.   }
  56.  
  57. /**********************************************************
  58.  * 
  59.  * STEP 7:  Flip edges in bottom layer.
  60.  *
  61.  *********************************************************/
  62.   loopCount = 0;
  63.   do {
  64.     if (++loopCount > 24) return false;
  65. /*  
  66.  *  At this point, all the edge cubes in the bottom layer 
  67.  *  are in the correct positions, but perhaps not in the 
  68.  *  correct orientation.  
  69.  *
  70.  *  Exit if all edge cubes have the proper orientation.
  71.  */
  72.     if (DF_F == F && DR_R == R &&
  73.         DB_B == B  && DL_L == L)
  74.       break;
  75. /*  
  76.  *  At least one edge cubes does not have the proper 
  77.  *  orientation.  The cube has the property that an even
  78.  *  number of edge cubes need to be flipped.
  79.  */
  80.     if (DF_F == D) {
  81.       if (DL_L == D) {
  82.         F1D1U3R2D2U2L1D1L3U2D2R2U1D3F3D3;
  83.       } else if (DB_B == D) {
  84.         F1D1U3R2D2U2L1D2L3U2D2R2U1D3F3D2;
  85.       } else if (DR_R == D) {
  86.         F1D1U3R2D2U2L1D3L3U2D2R2U1D3F3D1;
  87.       }
  88.     } else if (DL_L == D) {
  89.       if (DB_B == D) {
  90.         L1D1U3F2D2U2B1D1B3U2D2F2U1D3L3D3;
  91.       } else if (DR_R == D) {
  92.         L1D1U3F2D2U2B1D2B3U2D2F2U1D3L3D2;
  93.       } else if (DF_F == D) {
  94.         L1D1U3F2D2U2B1D3B3U2D2F2U1D3L3D1;
  95.       }
  96.     } else if (DB_B == D) {
  97.       if (DR_R == D) {
  98.         B1D1U3L2D2U2R1D1R3U2D2L2U1D3B3D3;
  99.       } if (DF_F == D) {
  100.         B1D1U3L2D2U2R1D2R3U2D2L2U1D3B3D2;
  101.       } else if (DL_L == D) {
  102.         B1D1U3L2D2U2R1D3R3U2D2L2U1D3B3D1;
  103.       }
  104.     } else if (DR_R == D) {
  105.       if (DF_F == D) {
  106.         R1D1U3B2D2U2F1D1F3U2D2B2U1D3R3D3;
  107.       } else if (DL_L == D) {
  108.         R1D1U3B2D2U2F1D2F3U2D2B2U1D3R3D2;
  109.       } else if (DB_B == D) {
  110.         R1D1U3B2D2U2F1D3F3U2D2B2U1D3R3D1;
  111.       }
  112.     }
  113.   } while(true);
  114.   return (true);
  115. }